/*
 * Copyright 2016-2018 TVI Go Easy.
 * Created on 2018/1/29 16:39
 */
package com.tvi.cloud.license.service;

import com.tvi.cloud.license.client.OrganizationDiscoveryClient;
import com.tvi.cloud.license.client.OrganizationFeignClient;
import com.tvi.cloud.license.client.OrganizationRibbonClent;
import com.tvi.cloud.license.model.Organization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 组织远程访问服务
 *
 * @author mechanic
 */
@Service
public class OrganizationService {
    @Autowired
    OrganizationFeignClient feignClient;

    @Autowired
    OrganizationRibbonClent ribbonClent;

    @Autowired
    OrganizationDiscoveryClient discoveryClient;

//    @Autowired
//    Oauth2RestTemplateClient oauth2RestTemplateClient;

//    @HystrixCommand
    public Organization retrieveOrgInfo(String organizationId, String clientType){
        Organization organization = null;
//        organization = oauth2RestTemplateClient.getOrganization(organizationId);
        switch (clientType) {
            case "feign":
                System.out.println("I am using the feign client");
                organization = feignClient.getOrganization(organizationId);
                break;
            case "ribbon":
                System.out.println("I am using the ribbon client");
                organization = ribbonClent.getOrganization(organizationId);
                break;
            case "discovery":
                System.out.println("I am using the discovery client");
                organization = discoveryClient.getOrganization(organizationId);
//                organization = oauth2RestTemplateClient.getOrganization(organizationId);
                break;
            default:
                organization = feignClient.getOrganization(organizationId);
        }

        return organization;
    }
}
